package com.foreknow.springboot.controller;

import com.foreknow.springboot.po.Orders;
import com.foreknow.springboot.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SuppressWarnings({"all"})
/**
 * @author xiaoming
 * @version jdk1.8
 * @date 2022/8/13 22:34
 * @function:
 */
@RestController
@RequestMapping("/OrdersController")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    //http://localhost:8089/elm/OrdersController/createOrder?userId=123456&businessId=10001&daId=15&orderTotal=25
    @RequestMapping("/createOrder")
    public int createOrder(Orders orders){
        return ordersService.saveOrder(orders.getUserId(),orders.getBusinessId(),orders.getDaId(),orders.getOrderTotal());
    }

    //http://localhost:8089/elm/OrdersController/getOrdersById?orderId=1
    @RequestMapping("/getOrdersById")
    public Orders getOrdersById(Orders orders){
        return ordersService.getOrdersById(orders.getOrderId());
    }

    //http://localhost:8089/elm/OrdersController/listOrdersByUserId?userId=11111111111
    @RequestMapping("/listOrdersByUserId")
    public List<Orders> listOrdersByUserId(Orders orders){
        return ordersService.listOrdersByUserId(orders.getUserId());
    }


}
